package c.常用类;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Test {
    public static void main1(String[] args)throws Exception {
        Date d=new Date();
        System.out.println(d);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s=sdf.format(d);
        System.out.println(s);

        //下面把字符串转Date
        s="2022-9-30 17:30:00";
        d=sdf.parse(s);
        System.out.println(d);
    }//2021-8-30 8:54

    public static void main2(String[] args) {
        Calendar c=Calendar.getInstance();

        c.add(Calendar.DATE,1);
        System.out.println(c.get(Calendar.DATE));
        Date d=c.getTime();
        c.setTime(d);
    }

    public static void main(String[] args)throws Exception {
        String s="2023-6-8 15:35:30";
        SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d=sd.parse(s);
        Calendar c=Calendar.getInstance();
        c.setTime(d);
        System.out.println(c.get(Calendar.YEAR));
        System.out.println(c.getTimeInMillis());
        d=new Date();
        System.out.println(d.getTime());
    }
}
